//
// Created by martin on 8/3/21.
//
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "session.h"

Session *session_new()
{
    Session *s = (Session *) malloc(sizeof(Session));
    if (!s) {
        return NULL;
    }
    bzero(s, sizeof(Session));

    // 初始化ip，端口信息
    strcpy(s->serv_ip, config_getIP());
    s->serv_data_port = config_getDataPort();

    // 初始化当前工作目录
    s->dir = dir_new(config_getRootDir());
    dir_print(s->dir);

    return s;
}

void session_free(Session *s)
{
    if (!s) return;
    if (s->dir) {
        dir_free(s->dir);
        s->dir = NULL;
    }
    free(s);
}
